<?php
/**
* 商品属性表管理模型
*/
class GoodsAttrModel extends Model{
    public $table='goods_attr';
    
    /*添加商品属性
     **/
    public function addAttr($gid){
        $attr=isset($_POST['attr'])?$_POST['attr']:array();
		//添加类型属性（不可挑选的）
		foreach ($attr as $k => $v) {
			if($v=='0') continue;
			$data=array(
				'attr_value'=>$v,
				'subjoin'=>0,
				'goods_gid'=>$gid,
				'tp_aid'=>$k
			);
			$this->add($data);
		}
		//添加型号属性（可挑选的）
		$spec=isset($_POST['spec'])?$_POST['spec']:array();
		$addPrice=isset($_POST['addPrice'])?$_POST['addPrice']:array();
		foreach ($spec as $k => $s) {
			foreach ($s as $key => $v) {
				if($v=='0'||$v=='') continue;
				$data=array(
					'attr_value'=>$v,
					'subjoin'=>$addPrice[$k][$key],
					'goods_gid'=>$gid,
					'tp_aid'=>$k				
				);
				$this->add($data);
			}
		}
    }
	
	/*编辑商品属性
	 **/
	public function editAttr(){
//		p($_POST);
	    $gid=Q('post.gid',0,'intval');
		$this->where("goods_gid={$gid}")->delete();
		$this->addAttr($gid);
	}
	
	
	
	
	
	
	
	
	

}
    
    
    
?>